//管理设备数据相关
import {defineStore} from "pinia";
import {ref} from "vue";
import {
    useGetAllEquipmentTransferFormAPI,
    useGetAllEquipmentTransferCountAPI,
    useDeleteOneByIdAPI,
    useGetByALLTypeNameAPI,
    useGetByBetweenTimeAPI, useGetAllByTypeNameCountsAPI, useGetByBetweenTimesCountSAPI, useGetOneByIdAPI
} from '@/apis/equipmentTransfer.ts';
import {RouteParamValue} from "vue-router";

export const useEquipmentTransferStore=defineStore('equipmentTransfer',()=>{

        //1.定义菜单的数据的state
        const equipmentTransferList=ref([]);
        const equipmentTransferCount=ref(Number);
        const equipTransferData=ref({});

        //分页查询所有数据
        const getEquipmentTransferList=async (current:number,pageSize:number)=>{
            const res=await useGetAllEquipmentTransferFormAPI(current,pageSize);
            equipmentTransferList.value=res.data;
        }
        //  配合分页查询所有数据接口，查询所有数据条数
        const getEquipmentTransferCounts=async ()=>{
            const res=await useGetAllEquipmentTransferCountAPI();
            equipmentTransferCount.value=res.data;
        }

        // 根据设备id删除一条设备记录
        const deleteOneById=async (id:number)=>{
            await useDeleteOneByIdAPI(id);
        }


        // 根据多类型名称查询多条设备转移记录
        const getByAllTypeName= async (name:string,current: number, pageSize: number)=>{
            const res=await useGetByALLTypeNameAPI(name,current,pageSize);
            equipmentTransferList.value=res.data;
        }

        // 配合根据多类型名称查询多条设备转移记录接口，查询符合条件的数据所有条数用于分页组件
        const getByAllTypeNameCounts=async (name:string)=>{
            const res=await useGetAllByTypeNameCountsAPI(name);
            equipmentTransferCount.value=res.data;
        }


        // 根据时间段查询多条设备装移记录
        const getByBetweenTime=async (startTime:Date,endTime:Date,current:number,pageSize:number)=>{
            const res=await useGetByBetweenTimeAPI(startTime,endTime,current,pageSize);
            equipmentTransferList.value=res.data;
        }

        // 配合根据时间段查询多条设备转移记录接口，查询符合条件的数据所有条数用于分页组件
        const getByBetweenTimeCounts=async (startTime:Date,endTime:Date)=>{
            const res=await useGetByBetweenTimesCountSAPI(startTime,endTime);
            equipmentTransferCount.value=res.data;
        }

        // 根据Id获取一条数据
        const getOneByIdStore=async (id:string|RouteParamValue[])=>{
            const res=await useGetOneByIdAPI(id);
            equipTransferData.value=res.data;
        }


        //3.以对象的格式把state和action return
        return {
            equipmentTransferList,equipmentTransferCount,
            getEquipmentTransferList,getEquipmentTransferCounts,
            deleteOneById,getByAllTypeName,getByBetweenTime,getByAllTypeNameCounts,
            getByBetweenTimeCounts,equipTransferData,getOneByIdStore
        }
    }

)